package com.autumn.xa.a.offerdemo;

import java.util.concurrent.CountDownLatch;

/**
 * ClassName: CacheLine
 *
 * @Description:
 * @Author: wangqiuyang
 * @Date: 2022/6/17 2:29 下午
 * History:
 * <author>          <time>          <version>          <desc>
 * wangqiuyang    2022/6/17 2:29 下午   @Version 1.0        描述
 */
public class CacheLine {
    public static long COUNT = 1000000000L;

    public static class T {
//        private long p1, p2 , p3 , p4 , p5 , p6 , p7;
        public long s = 0L;
//        private long p11 , p22 , p33 , p44 , p55 , p66 , p77;
    }

    public static T[] arr = new T[2];

    static {
        arr[0] = new T();
        arr[1] = new T();
    }

    public static void main(String[] args) throws Exception {
        CountDownLatch latch = new CountDownLatch(2);

        Thread t1 = new Thread(() -> {
            for (long i = 0; i < COUNT; i++) {
                arr[0].s = i;
            }

            latch.countDown();
        });

        Thread t2 = new Thread(() -> {
            for (long i = 0; i < COUNT; i++) {
                arr[1].s = i;
            }

            latch.countDown();
        });

        final long start = System.nanoTime();
        t1.start();
        t2.start();
        latch.await();
        System.out.println((System.nanoTime() - start) / 1000000 + "mm");
    }
}
